#pragma once
#include "Stdafx.h"
#include "Logger.h"
#include "Image.h"

namespace Pulpy
{
	class Sprite
	{
	private:
		unsigned short _Total;
		unsigned short  _Cols;
		unsigned short  _Rows;
		float _FrameWidth;
		float _FrameHeight;
		float _MinX;
		float _MaxX;
		float _MinY;
		float _MaxY;
		TextureImage _Image;
		
	public:
		Sprite():_Total(0),_Cols(0),_Rows(0),_FrameWidth(0),_FrameHeight(0),_MinX(0),_MaxX(0),_MinY(0),_MaxY(0) { }
		Sprite(unsigned short col, unsigned short row, char* filename):_Total(0),_Cols(col),_Rows(row),_MinX(0),_MaxX(0),_MinY(0),_MaxY(0)
		{
			if(!LoadTGA(&_Image, filename))
				Logger::getInstance().addLog("Sprite::Error Loading File: ", false);
			else
				Logger::getInstance().addLog("Sprite::Loaded File: ", false);
			Logger::getInstance().addLog(filename);

			_FrameWidth = _Image.width / (float)_Cols / _Image.width;
			_FrameHeight = _Image.height / (float)_Rows / _Image.height;
			
		}
		~Sprite() { delete &_Image; _Total = 0; _Cols = 0; _Rows = 0; _FrameWidth = 0; _FrameHeight = 0; _MinX = 0; _MaxX = 0; _MinY = 0; _MaxY = 0;  }
		void setIndex(unsigned short target) 
		{ 
			int tr = target / _Cols;
			int tc = (target % _Cols);
			
			_MinX = tc * _FrameWidth;
			_MinY = tr * _FrameHeight;
			_MaxX = _MinX + _FrameWidth;
			_MaxY = _MinY + _FrameHeight;
		}
		GLuint getTexID() { return _Image.texID; }
		float getMinX() { return _MinX; }
		float getMinY() { return _MinY; }
		float getMaxX() { return _MaxX; }
		float getMaxY() { return _MaxY; }
	};
}